package com.hbx.controller;

import com.hbx.constant.TableEnum;
import com.hbx.logs.OperaTypeEnum;
import com.hbx.logs.annotation.MarkLog;
import com.hbx.service.AdminService;
import com.hbx.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
 * @Project:resource-sharing-platform-java
 * @Author:hbx
 *
 * */

@RestController
@Api(tags = "管理处理器")
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;


    @ApiOperation("添加敏感词")
    @MarkLog(operate = OperaTypeEnum.INSERT, desc = "添加敏感词", tables = TableEnum.REDIS)
    @RequestMapping(value = "/addSensitive", method = RequestMethod.POST)
    public Result<String> addSensitive(String sensitive){
        Result<String> result = new Result<>();
        if (!StringUtils.hasLength(sensitive)) {
            result.setCode(201).setData("sensitive为必传项");
            return result;
        }
        adminService.addSensitive(sensitive, result);
        return result;
    }

    @ApiOperation("移除敏感词")
    @MarkLog(operate = OperaTypeEnum.DELETE, desc = "移除敏感词", tables = TableEnum.REDIS)
    @RequestMapping(value = "/removeSensitive", method = RequestMethod.GET)
    public Result<String> removeSensitive(String sensitive){
        Result<String> result = new Result<>();
        if (!StringUtils.hasLength(sensitive)) {
            result.setCode(201).setData("sensitive为必传项");
            return result;
        }
        adminService.removeSensitive(sensitive, result);
        return result;
    }

    @ApiOperation("获取敏感词列表")
    @MarkLog(operate = OperaTypeEnum.SELECT, desc = "获取敏感词列表", tables = TableEnum.REDIS)
    @RequestMapping(value = "/getSensitiveList", method = RequestMethod.GET)
    public Result<List<String>> getSensitiveList(){
        Result<List<String>> result = new Result<>();
        adminService.getSensitiveList(result);
        return result;
    }
}
